<template>
    <div>
      <van-nav-bar
         title="黑马头条-登录"
      />
      <van-form @submit="onSubmit">
  <van-field
    v-model="FormLogin.mobile"
    name="手机号"
    label="手机号"
    placeholder="请输入手机号"
    required
    :rules="[{ required: true, message: '这里填写手机号哦',pattern:/^1[3-9]\d{9}$/ }]"
  />
  <van-field
    v-model="FormLogin.code"
    type="password"
    name="密码"
    label="密码"
    placeholder="密码"
    required
    :rules="[{ required: true, message: '这里写密码哦', pattern:/^\d{6}$/ }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" :disabled="isloading" :loading="isloading">提交</van-button>
  </div>
</van-form>
    </div>
</template>

<script>
import { mapActions } from 'vuex'
import { Notify } from 'vant'
export default {
  name: 'Login',
  data () {
    return {
      username: '',
      password: '',
      FormLogin: {
        mobile: '17815746167',
        code: '246810'
      },
      isloading: false
    }
  },
  methods: {
    ...mapActions(['asyncloginAction']),
    async onSubmit () {
      this.isloading = true
      try {
        await this.asyncloginAction(this.FormLogin)
        Notify({ type: 'success', message: '登陆成功' })
        this.isloading = false
        this.$router.replace('/layout')
        // this.$router.push('/layout')
        // this.$router用于路由跳转，有两个方法：
        // replace不可以退回，但是push可以退回login页面
      } catch (err) {
        Notify({ type: 'warning', message: '登陆失败' })
        this.isloading = false
      }
    }
  }
}
</script>

<style lang="less" scoped>
// .van-nav-bar{
//    background: #007bff;
// }
// /deep/.van-nav-bar__title{  //因为有scoped，所以要用穿透符，
//     color:#fff            //每个预处理器的穿透符不一样，less的是/deep/
// }
</style>
